﻿package view.popup
{
    import com.core.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import manager.*;
    import plugin.taskdialog.consts.*;
    import uiresource.popup.*;

    public class ShowDownCtrl extends ShowDownUI implements IDialogUI
    {
        private var sx:int;
        private var sy:int;
        private var tostageid:int;
        private var timeoutID:uint;
        private var stime:int = 0;
        private var background:Sprite;
        private var tnpc:int;
        private var _tipstr:String = "";

        public function ShowDownCtrl()
        {
            return;
        }// end function

        override protected function createChildren() : void
        {
            super.createChildren();
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            this.background = new Sprite();
            this.background.graphics.beginFill(0, 0.5);
            this.background.graphics.drawRect(0, 0, GlobalLayer.instance.root.stage.stageWidth, GlobalLayer.instance.root.stage.stageHeight);
            this.background.graphics.endFill();
            this.background.addEventListener(MouseEvent.MOUSE_DOWN, this.onDown);
            PluginManager.instance.alertContainer.addChild(this.background);
            var _loc_1:Boolean = false;
            this.visible = false;
            this.background.visible = _loc_1;
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            sureBtn.addEventListener(MouseEvent.CLICK, this.onSureFly);
            btn_close.addEventListener(MouseEvent.CLICK, this.closeHandler);
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.onDown);
            GlobalLayer.instance.root.addEventListener(Event.RESIZE, this.resizeHandler);
            return;
        }// end function

        private function onSureFly(event:MouseEvent) : void
        {
            this.toFly();
            this.close();
            return;
        }// end function

        private function closeHandler(event:MouseEvent) : void
        {
            if (this.timeoutID)
            {
                clearInterval(this.timeoutID);
            }
            this.timeoutID = 0;
            this.close();
            return;
        }// end function

        public function show(param1:Object) : void
        {
            this.sx = param1[0];
            this.sy = param1[1];
            this.tostageid = param1[2];
            this.tnpc = param1[3];
            var _loc_2:Boolean = true;
            this.visible = true;
            this.background.visible = _loc_2;
            this.stime = 5;
            lab3.text = "5秒";
            if (this.timeoutID)
            {
                clearInterval(this.timeoutID);
            }
            this.timeoutID = setInterval(this.upDateTime, 1000);
            return;
        }// end function

        private function upDateTime() : void
        {
            if (this.stime > 1)
            {
                var _loc_1:String = this;
                var _loc_2:* = this.stime - 1;
                _loc_1.stime = _loc_2;
                lab3.text = this.stime + "秒";
            }
            else
            {
                this.toFly();
            }
            return;
        }// end function

        private function toFly() : void
        {
            var _loc_2:Point = null;
            var _loc_3:Array = null;
            if (this.timeoutID)
            {
                clearInterval(this.timeoutID);
            }
            var _loc_1:* = UserData.getUserData("death");
            if (_loc_1)
            {
                this.close();
                return;
            }
            this.stime = 0;
            this.stime = 5;
            PluginManager.instance.sendToServer("taskdialog", CMDTaskdialog.Fly, {x:this.sx, y:this.sy, tostageid:this.tostageid});
            this.close();
            if (this.tnpc > 0)
            {
                ModelProxy.change("data", "taskfindpath", this.tnpc);
                this.tnpc = 0;
                return;
            }
            if (this.tostageid == 1097)
            {
                ModelProxy.change("zone", "autodig", null);
            }
            else
            {
                _loc_2 = new Point(this.sx, this.sy);
                _loc_3 = [this.sx, this.sy, 0, this.tostageid];
                ModelProxy.change("data", "taskfindmaster", _loc_3);
                ModelProxy.change("zone", "autoMove", {x:this.sx, y:this.sy, tostageid:this.tostageid, onhorse:true});
            }
            return;
        }// end function

        public function close() : void
        {
            var _loc_1:Boolean = false;
            this.visible = false;
            this.background.visible = _loc_1;
            return;
        }// end function

        private function onDown(event:MouseEvent) : void
        {
            event.stopImmediatePropagation();
            return;
        }// end function

        private function resizeHandler(event:Event) : void
        {
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            this.background.width = GlobalLayer.instance.root.stage.stageWidth;
            this.background.height = GlobalLayer.instance.root.stage.stageHeight;
            return;
        }// end function

    }
}
